-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
labhub.py: add migrate_issue plugin #521
base: master
Are you sure you want to change the base?
Conversation
plugins/labhub.py
Outdated
@@ -381,3 +381,100 @@ def pr_stats(self, msg, match): | |||
state=type(self).community_state(pr_count) | |||
) | |||
yield reply | |||
|
|||
@re_botcmd(pattern=r'^migrate\s+https://github.com/([^/]+)/([^/]+)/+issues/(\d+)\s+https://github.com/([^/]+)/([^/]+)/*$', # Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this workable for gitlab repos as well. The whole point of labhub is to provide a unified front for both GitHub and GitLab, and hence the name LabHub 😉
plugins/labhub.py
Outdated
yield 'Second repository not owned by our org.' | ||
return | ||
|
||
if (repo_name_orig in self.REPOS) and (repo_name_final in self.REPOS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use, if not...
so we can remove the reduntant if block and the contained pass
statement
plugins/labhub.py
Outdated
yield 'Repository does not exist!' | ||
return | ||
|
||
if self.TEAMS[self.GH_ORG_NAME + ' maintainers'].is_member(user): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
plugins/labhub.py
Outdated
old_labels = old_issue.labels | ||
|
||
except RuntimeError: | ||
yield 'Issue does not exist!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuntimeError
in IGitt is not always 404s 😅
plugins/labhub.py
Outdated
if str(old_issue.state) == 'closed': | ||
yield 'Issue cannot be migrated as it has been closed already.' | ||
return | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else block is not needed, remove it
plugins/labhub.py
Outdated
url1 = 'https://github.com/{}/{}/issues/{}' | ||
new_issue_title = old_issue.title | ||
new_issue_description = old_issue.description.rstrip() | ||
extra_msg = '\n\nMigrated issue from '+url1.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe include the author as well? Migrate issue opened by @author from ...
so the author the issue follows new issue as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying the same, but there seems to be some problem with the IGitt
module I have installed on my system using pip
, as it says author of the issue is not an attribute even though I find this method here: https://gitlab.com/gitmate/open-source/IGitt/blob/master/IGitt/GitHub/GitHubIssue.py and I am not particularly sure why but might be some problem with my system... 😅
plugins/labhub.py
Outdated
' by @' + str(user) | ||
|
||
new_issue = self.REPOS[repo_name_final].create_issue( | ||
new_issue_title, new_issue_description+extra_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just concatenate this above, concatenation in function args doesn't look good and is confusing
plugins/labhub.py
Outdated
|
||
old_comm = old_issue.comments | ||
|
||
for i in range(len(old_comm)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use for comment in old_issue.comments
and get rid of few lines of code here 😉
plugins/labhub.py
Outdated
yield 'Second repository not owned by our org.' | ||
return | ||
|
||
if (repo_name_orig not in self.REPOS) or (repo_name_final not in self.REPOS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (85 > 80)
Origin: LineLengthBear, Section: all.linelength
.
plugins/labhub.py
Outdated
yield 'Repository does not exist!' | ||
return | ||
|
||
if (self.TEAMS[self.GH_ORG_NAME + ' maintainers'].is_member(user) == False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength
.
plugins/labhub.py
Outdated
new_issue_title = old_issue.title | ||
new_issue_description = old_issue.description.rstrip() | ||
issue_author = old_issue.author.username | ||
extra_msg = '\n\nMigrated issue originally opened by @' + issue_author + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (82 > 80)
Origin: LineLengthBear, Section: all.linelength
.
plugins/labhub.py
Outdated
|
||
for comment in old_issue.comments: | ||
comm_text = comment.body.rstrip() | ||
comm_url = url1.format(orig_host, org, repo_name_orig, issue_number) + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength
.
plugins/labhub.py
Outdated
comm_url = url1.format(orig_host, org, repo_name_orig, issue_number) + \ | ||
'#issuecomment-' + str(comment.number) | ||
new_body = comm_text + '\n\nOriginally written by @' + \ | ||
comment.author.username + ' on ' + str(comment.updated) + ' UTC' + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength
.
plugins/labhub.py
Outdated
url2 = 'https://{}.com/{}/{}/issues/{}'.format( | ||
final_host, org, repo_name_final, new_issue.number) | ||
|
||
migrated_comment = 'Issue has been migrated to another [repository](' + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (81 > 80)
Origin: LineLengthBear, Section: all.linelength
.
Requested changes made, @meetmangukiya |
f03dd02
to
6b8f154
Compare
tests/labhub_test.py
Outdated
@@ -25,6 +25,7 @@ def setUp(self): | |||
|
|||
self.mock_org = create_autospec(github3.orgs.Organization) | |||
self.mock_gh = create_autospec(github3.GitHub) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated change.
tests/labhub_test.py
Outdated
mock_maint_team.is_member.return_value = False | ||
|
||
labhub.TEAMS = { | ||
'coala maintainers': mock_maint_team, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent only 4 spaces
tests/labhub_test.py
Outdated
# No issue exists | ||
mock_maint_team.is_member.return_value = True | ||
self.mock_repo.get_issue = Mock(side_effect=RuntimeError('Error message',404)) | ||
testbot.assertCommand(cmd.format('coala', 'a', '21','coala','b'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing whitespace between args
tests/labhub_test.py
Outdated
'has been closed already') | ||
# Migrate issue | ||
mock_maint_team.is_member.return_value = True | ||
mock_iss = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use mock_issue
instead of shorted name
Requested changes made, @jayvdb |
tests/labhub_test.py
Outdated
# Migrate issue | ||
mock_maint_team.is_member.return_value = True | ||
mock_issue = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) | ||
issue2 = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is one called mock_issue
and the other issue2
? that is confusing.
plugins/labhub.py
Outdated
try: | ||
assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME | ||
except AssertionError: | ||
yield 'First repository not owned by our org.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First & second -> source & target
plugins/labhub.py
Outdated
org2 = match.group(6) | ||
repo_name_final = match.group(7) | ||
|
||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace try
with if
plugins/labhub.py
Outdated
yield 'Issue cannot be migrated as it has been closed already.' | ||
return | ||
|
||
url1 = 'https://{}.com/{}/{}/issues/{}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isnt a url .. it is a format string.
confusing because here url1
is a format string, but below url2
is a real complete url.
plugins/labhub.py
Outdated
new_issue_title = old_issue.title | ||
new_issue_description = old_issue.description.rstrip() + '\n\n' | ||
issue_author = old_issue.author.username | ||
ext_msg = 'Migrated issue originally opened by @' + issue_author + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls dont use line continuations (\
)
plugins/labhub.py
Outdated
else: | ||
raise RuntimeError(sterr, errno) | ||
|
||
if str(old_issue.state) == 'closed': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is safer to check that it is open.
then new states wont surprise everyone.
plugins/labhub.py
Outdated
try: | ||
assert org2 == self.GH_ORG_NAME or org2 == self.GL_ORG_NAME | ||
except AssertionError: | ||
yield 'Second repository not owned by our org.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is only one message, you can use return 'foo'
instead of yield
& return
Changes made @jayvdb |
plugins/labhub.py
Outdated
org = match.group(2) | ||
repo_name_orig = match.group(3) | ||
issue_number = match.group(4) | ||
user = msg.frm.nick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a bit strange seeing this variable mixed in amoung all the regex matches.
please read every line of your diff and ask yourself if it can be improved.
Made changes as requested, @jayvdb |
@@ -381,3 +381,90 @@ def pr_stats(self, msg, match): | |||
state=type(self).community_state(pr_count) | |||
) | |||
yield reply | |||
|
|||
@re_botcmd(pattern=r'^migrate\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/+issues/(\d+)\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/*$', # Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the regex won't work for gitlab sub groups, see regex for other commands to see how its done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this regex is most likely be duplicated in every command, make a new constant with the regex to match github/gitlab url, and then append it to your command. Do this as part of another issue after this is complete 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meetmangukiya , I used the same regex as used in unassign_cmd and it uses the same regex. How should I go about this? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about we only capture the URL here, without using regex to parse it, and then split it with a helper function that can be re-used in each command which takes a git hoster URL ?
plugins/labhub.py
Outdated
if target_repo not in self.REPOS: | ||
return 'Target repository does not exist.' | ||
|
||
# Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
plugins/labhub.py
Outdated
source_url = 'https://{}.com/{}/{}/issues/{}'.format( | ||
source_host, source_org, source_repo, issue_number) | ||
|
||
# Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and make the string multiline, something like
a = ('some long string which doesnt fit in 80 chars'
'Next part of the string. This both will be concantenated into one')
plugins/labhub.py
Outdated
source_issue.title, target_issue_desc) | ||
target_issue.labels = source_labels | ||
|
||
# Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
plugins/labhub.py
Outdated
comment_ext = '\n\nOriginally commented by @{} on {} UTC and can be seen [here]({})' | ||
|
||
for comment in source_issue.comments: | ||
comm_url = source_url + '#issuecomment-' + str(comment.number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the case for gitlab comments, use IGitt API to get comment link, if it doesn't exist, make upstream contribution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be excluding the comment URLs for the current PR and will make another PR when upstream contribution in IGitt is made.
plugins/labhub.py
Outdated
target_issue.labels = source_labels | ||
|
||
# Ignore LineLengthBear, PyCodeStyleBear | ||
comment_ext = '\n\nOriginally commented by @{} on {} UTC and can be seen [here]({})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the time returned has no UTC offset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it on it on my own forks and there was no UTC offset included there. However, I wasn't able to find documentation explicitly mentioning anything about offsets 😅
Will do @meetmangukiya |
@random-access7 can you please make the requested changes? |
@nvzard, will do by tonight. |
migrate_issue plugin that adds ability to migrate an issue from a source repo to target repo, both owned by the org. Issue title, issue description and all comments are copied with a few additional details appended to the description and comments. Source issue is referenced in the target issue and closed after the migration is completed. Closes coala#518
@gitmate-bot rebase |
Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently |
Automated rebase failed! Please rebase your pull request manually via the command line. Reason:
|
@random-access7 can you please resolve the merge conflicts? And we will make sure it merges before anything else so it doesn't lead to more conflicts |
Introduce migrate_issue plugin that adds ability
to migrate an issue from a source repo to target
repo, both owned by the org.
Issue title, issue description and all comments
are copied with a few additional details appended to
the the description and comments. Source issue is
referenced in the target issue and is closed after
the migration is complete.
Closes #518
Reviewers Checklist
botcmd
andre_botcmd
decorators.